﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//51-aspx
public partial class _Default : System.Web.UI.Page
{
    BookManage bookmanage = new BookManage();
    ReaderManage readermanage = new ReaderManage();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "图书馆管理系统主页";
        DataSet bookds = bookmanage.GetBookSort("tb_bookinfo");
        gvBookSort.DataSource = bookds;
        gvBookSort.DataBind();

        DataSet readerds = readermanage.GetReaderSort("tb_reader");
        gvReaderSort.DataSource = readerds;
        gvReaderSort.DataBind();
    }
    protected void gvBookSort_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }
    }
    protected void gvReaderSort_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        gvBookSort_RowDataBound(sender, e);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
        Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
        this.EnableViewState = false;
        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        this.gvBookSort.RenderControl(oHtmlTextWriter);//GV2是Gridview的ID名称
        Response.Write(oStringWriter.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }
}
